﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Xps.Serialization;

using System.Diagnostics;
using System.Drawing.Drawing2D;

namespace SuperKit
{
    class FastPackExe : CommandExecutor
    {
        public const string FAST_PACK_PY = @"C:\Project\[Python]\WebViewer\fast_pack.py";
        string destFile;
        bool isOverride;

        public FastPackExe(ArgReader arg, IExecutorOwner form, string fpath) : base(arg, form, fpath)
        {
            destFile = arg.GetParameter("-file");
            isOverride = arg.IsContain("-override");
        }

        public override void Execute()
        {
            string save_path = Kit.IsEmpty(destFile) ? string.Format("{0}.pak", FilePath) : destFile;
            if (isOverride == false) {
                if (File.Exists(save_path)) {
                    Flush("{0} 已经存在！", save_path);
                    End();
                    return;
                }
            }

            string script_args = $"-pack \"{FilePath}\" -o \"{save_path}\"";
            Flush("{0} {1}", FAST_PACK_PY, script_args);
            RunPythonScript(FAST_PACK_PY, script_args);
        }
  
        static public void RunPythonScript(string scriptPath, string script_args) {
            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = ConfigReader.Instance.PythonExe; // 替换为你的Python解释器路径  
            start.Arguments = $"\"{scriptPath}\" {script_args}"; // 替换为你的Python脚本路径              
            start.UseShellExecute = true;
            start.RedirectStandardOutput = false;
            using (Process process = Process.Start(start)) {
                process.WaitForExit();
            }
        }
    }
}
